//
//  MyCollectionViewController.m
//  Socrates
//
//  Created by shy on 15/4/12.
//  Copyright (c) 2015年 shy. All rights reserved.
//

#import "MyCollectionViewController.h"

#import "HomeCell.h"
#import "ActivityDetailViewController.h"
#import "UserInfoViewController.h"

typedef enum {
    kMe_about_us_item = 0,
    kMe_upgrade_version_item,
    kMe_share_friends_item,
    kLimitation_Num,
} MeItems;

static const int kLimitationRowHeight = 180;

@implementation MyCollectionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //here is the bug caused.
    self.navigationItem.title = @"首页";
    self.view.backgroundColor = [UIColor colorWithRed:239/255. green:239/255. blue:244/255. alpha:1.];
    [self.tableView registerNib:[UINib nibWithNibName:@"HomeCell" bundle:nil] forCellReuseIdentifier:@"JoinedCellIdentifier"];
    self.tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
    // Do any additional setup after loading the view, typically from a nib.
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 20;
}

- (UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 20)];
    view.backgroundColor = [UIColor colorWithRed:239/255. green:239/255. blue:244/255. alpha:1.];
    return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return kLimitationRowHeight;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return kLimitation_Num;
}

- (HomeCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *cellIdentifier = @"JoinedCellIdentifier";
    HomeCell *cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
        cell = [[HomeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    [cell.userImage addTarget:self action:@selector(clickUser) forControlEvents:UIControlEventTouchUpInside];
    switch ([indexPath row]) {
        case kMe_about_us_item:
            cell.activityName.text = @"周杰伦2015个人演唱会";
            cell.activityFee.text = @"288/人";
            cell.declareTime.text = @"1小时前";
            cell.time.text = @"2015/11/28 19:00";
            cell.location.text = @"北京 朝阳区 鸟巢体育馆";
            cell.numMale.text = @"11/18";
            cell.numFemale.text = @"12/21";
            cell.userName.text = @"AngelaBaby";
            cell.userAge.text = @"21";
            cell.userSchool.text = @"对外经贸大学";
            cell.likes.text = @"25";
            break;
        case kMe_upgrade_version_item:
            cell.activityName.text = @"周杰伦2015个人演唱会";
            cell.activityFee.text = @"288/人";
            cell.declareTime.text = @"1小时前";
            cell.time.text = @"2015/11/28 19:00";
            cell.location.text = @"北京 朝阳区 鸟巢体育馆";
            cell.numMale.text = @"11/18";
            cell.numFemale.text = @"12/21";
            cell.userName.text = @"AngelaBaby";
            cell.userAge.text = @"21";
            cell.userSchool.text = @"对外经贸大学";
            cell.likes.text = @"25";
            break;
        case kMe_share_friends_item:
            cell.activityName.text = @"周杰伦2015个人演唱会";
            cell.activityFee.text = @"288/人";
            cell.declareTime.text = @"1小时前";
            cell.time.text = @"2015/11/28 19:00";
            cell.location.text = @"北京 朝阳区 鸟巢体育馆";
            cell.numMale.text = @"11/18";
            cell.numFemale.text = @"12/21";
            cell.userName.text = @"AngelaBaby";
            cell.userAge.text = @"21";
            cell.userSchool.text = @"对外经贸大学";
            cell.likes.text = @"25";
            break;
        default:
            break;
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    ActivityDetailViewController *vc = [[ActivityDetailViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
    NSLog(@"click for detail");
}

- (void)clickUser {
    NSLog(@"have react.");
    UserInfoViewController *vc = [[UserInfoViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

@end
